package com.whjz.dcfs.gis.struts.action;

import com.whjz.dcfs.jzxx.dao.IDcfsHjjcdJbxxDAO;
import com.whjz.dcfs.jzxx.dao.IDcfsJzSbJbxxDAO;
import com.whjz.dcfs.jzxx.dao.IDcfsMgdJbxxDAO;
import com.whjz.dcfs.jzxx.model.DcfsHjjcdJbxx;
import com.whjz.dcfs.jzxx.model.DcfsJzSbJbxx;
import com.whjz.dcfs.jzxx.model.DcfsMgdJbxx;
import com.whjz.dcfs.util.BaseAction;
import org.apache.commons.collections.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

public class GisAction extends BaseAction{

	private DcfsJzSbJbxx dcfsJzSbJbxx;


	private static final long serialVersionUID = 1L;
	private DcfsMgdJbxx dcfsMgdJbxx;
	@Autowired
	public IDcfsJzSbJbxxDAO dcfsJzSbJbxxDAO;
	@Autowired
	public IDcfsMgdJbxxDAO dcfsMgdJbxxDAO;
	@Autowired
	public IDcfsHjjcdJbxxDAO dcfsHjjcdJbxxDAO;
	private DcfsHjjcdJbxx dcfsHjjcdJbxx;

	private static final Set<String> bdzSet = new HashSet<>(Arrays.asList("13MT0227",
			"02715071015_ESM100","02715071016_ESM100","02715071017_ESM100"));

	//地理信息页面点击查询
	public void getGis() throws Exception{
		getHttpServletResponse().setCharacterEncoding("utf-8");
		//如果传递的类型是153(变电站类型)
		int iconType;
		if("153".equals(dcfsJzSbJbxx.getYtbh())){
			dcfsJzSbJbxx.setYtbh("1");
			iconType = 4;
		}else if("1".equals(dcfsJzSbJbxx.getYtbh())){
			iconType = 2;
			dcfsJzSbJbxx.setYtbh("0");
		}else if("2".equals(dcfsJzSbJbxx.getYtbh())){
			//地图刚进来时初始化五个示范点
			iconType = 0;//混合类型
			dcfsJzSbJbxx.setYtbh("");
			dcfsJzSbJbxx.setJzsbbh("'13MT0227','02715071015_ESM100','02715071016_ESM100','02715071017_ESM100','EP-4B-02'");
		}else{
			iconType = 0;//混合类型
			dcfsJzSbJbxx.setYtbh("");
		}
		List<DcfsJzSbJbxx> list=dcfsJzSbJbxxDAO.getDcfsJzSbJbxxList(dcfsJzSbJbxx);
		StringBuffer sb = new StringBuffer();
		sb.append("[");

		if(CollectionUtils.isNotEmpty(list)){
			for(int i=0;i<list.size();i++){
				sb.append("{");
				sb.append("title:\"<span>"+list.get(i).getJzsbmc()+"</span>\",");
				sb.append("sbbh:\""+list.get(i).getJzsbbh()+"\",");
				if(bdzSet.contains(list.get(i).getJzsbbh())) {
					sb.append("sblx:" + 153 + ",");
				}else{
					sb.append("sblx:" + 0 + ",");
				}
				sb.append("name:\""+(list.get(i).getJzsbmc()==null?"":list.get(i).getJzsbmc())+"\",");
				sb.append("address:\""+(list.get(i).getJzdd()==null?"":list.get(i).getJzdd())+"\",");
				sb.append("content:\"编号："+list.get(i).getJzsbbh()+"<br/>");
				sb.append("基站名称："+(list.get(i).getJzsbmc()==null?"":list.get(i).getJzsbmc())+"<br/>");
				sb.append("地点："+(list.get(i).getJzsbazwz()==null?"":list.get(i).getJzsbazwz())+"<br/>");
				String jzsbbh = list.get(i).getJzsbbh();
				if(bdzSet.contains(list.get(i).getJzsbbh())) {
					sb.append("当前电场：<span id='mesure_" + jzsbbh + "'></span>&nbsp;是否达标：<span id='isMesureValid_" + jzsbbh + "'></span><br/>");
					sb.append("当前磁场：<span id='mesure2_" + jzsbbh + "'></span>&nbsp;是否达标：<span id='isMesure2Valid_" + jzsbbh + "'></span><br/>");
					sb.append("站点温度：<span id='temperature_" + jzsbbh + "'></span>&nbsp;站点湿度：<span id='humidity_" + jzsbbh + "'></span><br/><br/>");
				}else{
					sb.append("网络类型："+(list.get(i).getJzsbwllx()==null?"":list.get(i).getJzsbwllx())+"<br/><br/>");
				}
				sb.append("<a href='javascript:void(0)' onclick='loadSBXX(2,\\\""
						+list.get(i).getJzsbbh()+"\\\")'>详细情况</a>&nbsp;&nbsp;");
				double P2;
				if("".equals(list.get(i).getJzbcgl())||list.get(i).getJzbcgl()==null){
					P2=Math.log10(Double.valueOf("20"))*10+30;
				}else{
					P2=Math.log10(Double.valueOf(list.get(i).getJzbcgl()))*10+30;
				}
				sb.append("<a href='javascript:void(0)' onclick='loadQJDT(\\\""
						+list.get(i).getBdjd()+"\\\",\\\""
						+list.get(i).getBdwd()+"\\\",\\\""
						+list.get(i).getJzsbmc()+"\\\",\\\""+P2+"\\\")'>全景地图</a><br/><br/>");
				if(!"153".equals(list.get(i).getYtbh())) {
					sb.append("<a href='javascript:void(0)' onclick='loadTSXX(\\\""+list.get(i).getJzsbbh()+"\\\")'>投诉信息</a>&nbsp;&nbsp;");
					sb.append("<a href='javascript:void(0)' onclick='loadMXFX(\\\""+list.get(i).getBdjd()+"\\\",\\\""+list.get(i).getBdwd()+"\\\",\\\""+list.get(i).getJzsbmc()+"\\\",\\\""+P2+"\\\")'>模型分析</a><br/><br/>");
				}

				sb.append("周围敏感点：<select id='leibie'><option value='学校'>学校</option><option value='医院'>医院</option><option value='政府'>政府</option><option value='小区'>小区</option></select>"
						+"　<a href='javascript:void(0)' onclick='loadMGD(\\\""
						+list.get(i).getJzsbbh()+"\\\",\\\""
						+list.get(i).getBdjd()+"\\\",\\\""
						+list.get(i).getBdwd()+"\\\")'>搜索</a>\",");
				sb.append("point:\""+list.get(i).getBdjd()+"|"+list.get(i).getBdwd()+"\",");
				sb.append("icon: { w: 60, h: 60, l: 0, t: 1, x: 6, lb: 9 },");
				sb.append("isOpen: 0,");
				/*
				 * type=
				 * 1 dcfs.jpg
				 * 2 shudian.png
				 * 3 dianchi.png
				 * 4 biandianzhan.png
				 */
				if(iconType!=0) {
					sb.append("type:" + iconType);
				}else{
					if(bdzSet.contains(list.get(i).getJzsbbh())){
						sb.append("type:" + 4);
					}else{
						sb.append("type:" + 2);
					}
				}
				sb.append("}");
				if(i<list.size()-1){
					sb.append(",");
				}
			}
		}
		sb.append("]");
		getHttpServletResponse().getWriter().println(sb);
	}
	
	public void getJzsbMgdJbxx() throws Exception{
		getHttpServletResponse().setCharacterEncoding("utf-8");
		List<DcfsHjjcdJbxx> mgd_al=dcfsHjjcdJbxxDAO.getDcfsHjjcdJbxxListByCond(dcfsHjjcdJbxx);
		StringBuffer sb=new StringBuffer();
		sb.append("[");
		if(mgd_al!=null&&mgd_al.size()>0){
			for (int i = 0; i < mgd_al.size(); i++) {
				sb.append("{");
				sb.append("title:\"<span>"+(mgd_al.get(i).getJcdmc()==null?"":mgd_al.get(i).getJcdmc())+"</span>\",");
				sb.append("name:\""+(mgd_al.get(i).getJcdmc()==null?"":mgd_al.get(i).getJcdmc())+"\",");
				sb.append("content:\"<table width='409' border='0' cellspacing='0' cellpadding='0'><tr><td width='309'>地址：");
				
				sb.append((mgd_al.get(i).getHjzljkdz()==null?"":mgd_al.get(i).getHjzljkdz())+"</td><td rowspan='3'><img src='http://"+getHttpServletRequest().getServerName()+":"+getHttpServletRequest().getServerPort()+"' width='100' height='100' /></td></tr>");
				sb.append("<tr><td>方位："+(mgd_al.get(i).getJcdxdfw()==null?"":mgd_al.get(i).getJcdxdfw())+"</td></tr>");
				sb.append("<tr><td>垂直距离："+(mgd_al.get(i).getJcdxdjlcz()==null?"":mgd_al.get(i).getJcdxdjlcz())+"</td></tr>");
				sb.append("<tr><td>联系方式："+(mgd_al.get(i).getJcdxdjlsp()==null?"":mgd_al.get(i).getJcdxdjlsp())+"</td></tr></table>\",");
				sb.append("point:\""+mgd_al.get(i).getJkxtzbjd()+"|"+mgd_al.get(i).getJkxtzbwd()+"\",");
				sb.append("icon: { w: 60, h: 60, l: 0, t: 1, x: 6, lb: 9 },");
				sb.append("isOpen: 0,");
				sb.append("type:0");
				sb.append("}");
				
				if(i<mgd_al.size()-1){
					sb.append(",");
				}
			}
		}
		sb.append("]");
		getHttpServletResponse().getWriter().println(sb);
	}
	
	public void getJzsbJbxx() throws Exception{
		getHttpServletResponse().setCharacterEncoding("utf-8");
		DcfsJzSbJbxx list=dcfsJzSbJbxxDAO.getDcfsJzSbJbxxByPK(dcfsJzSbJbxx);
		StringBuffer sb=new StringBuffer();
		sb.append("{root:[");
		sb.append("{");
		sb.append("JZ_SB_BH:'"+(list.getJzsbbh()==null?"":list.getJzsbbh())+"',");
		sb.append("JZ_SB_MC:'"+(list.getJzsbmc()==null?"":list.getJzsbmc())+"',");
		sb.append("JZ_SB_XH:'"+(list.getJzsbxh()==null?"":list.getJzsbxh())+"',");
		sb.append("JZ_SB_WLLX:'"+(list.getJzsbwllx()==null?"":list.getJzsbwllx())+"',");
		sb.append("YT_MC:'"+(list.getYtmc()==null?"":list.getYtmc())+"',");
		sb.append("YT_BH:'"+(list.getYtbh()==null?"":list.getYtbh())+"',");
		sb.append("JZ_SB_AZWZ:'"+(list.getJzsbazwz()==null?"":list.getJzsbazwz())+"',");
		sb.append("JZ_SB_QYSJ:'"+(list.getJzsbqysj()==null?"":list.getJzsbqysj())+"',");
		sb.append("JZ_BCGL:'"+(list.getJzbcgl()==null?"":list.getJzbcgl())+"',");
		sb.append("JZ_ZPPZ:'"+(list.getJzzppz()==null?"":list.getJzzppz())+"',");
		sb.append("JZ_XXPD_1:'"+(list.getJzxxpd1()==null?"":list.getJzxxpd1())+"',");
		sb.append("JZ_XXPD_2:'"+(list.getJzxxpd2()==null?"":list.getJzxxpd2())+"',");
		sb.append("JZ_TXZY:'"+(list.getJztxzy()==null?"":list.getJztxzy())+"',");
		sb.append("JZ_FSTX_LX:'"+(list.getJzfstxlx()==null?"":list.getJzfstxlx())+"',");
		sb.append("JZ_FSTX_JHFS:'"+(list.getJzfstxjhfs()==null?"":list.getJzfstxjhfs())+"',");
		sb.append("JZ_FSTX_FWJ:'"+(list.getJzfstxfwj()==null?"":list.getJzfstxfwj())+"',");
		sb.append("JZ_FSTX_XPJ:'"+(list.getJzfstxxpj()==null?"":list.getJzfstxxpj())+"',");
		sb.append("JZ_FSTX_JD:'"+(list.getJzfstxjd()==null?"":list.getJzfstxjd())+"',");
		sb.append("JZ_FSTX_WD:'"+(list.getJzfstxwd()==null?"":list.getJzfstxwd())+"',");
		sb.append("JZ_FSTX_JSFS:'"+(list.getJzfstxjsfs()==null?"":list.getJzfstxjsfs())+"',");
		sb.append("JZ_FSTX_JSGD:'"+(list.getJzfstxjsgd()==null?"":list.getJzfstxjsgd())+"',");
		sb.append("JZ_FSTX_SL:'"+(list.getJzfstxsl()==null?"":list.getJzfstxsl())+"',");
		sb.append("JZ_BZ:'"+(list.getJzbz()==null?"":list.getJzbz())+"',");
		sb.append("JZ_BH:'"+(list.getJzbh()==null?"":list.getJzbh())+"',");
		sb.append("JZ_MC:'"+(list.getJzmc()==null?"":list.getJzmc())+"',");
		sb.append("JZ_DD:'"+(list.getJzdd()==null?"":list.getJzdd())+"',");
		sb.append("BD_JD:'"+(list.getBdjd()==null?"":list.getBdjd())+"',");
		sb.append("BD_WD:'"+(list.getBdwd()==null?"":list.getBdwd())+"',");
		sb.append("JZ_HP_ZT:'"+(list.getJzhpzt()==null?"":list.getJzhpzt())+"',");
		sb.append("JZ_YS_DW:'"+(list.getJzysdw()==null?"":list.getJzysdw())+"',");
		sb.append("JZ_YYS_XX:'"+(list.getJzyysxx()==null?"":list.getJzyysxx())+"',");
		sb.append("JZ_JC_DW:'"+(list.getJzjcdw()==null?"":list.getJzjcdw())+"',");
		sb.append("JZ_SB_QY:'"+(list.getJzsbqy()==null?"":list.getJzsbqy())+"'");
		sb.append("}");		
		sb.append("]");
		sb.append("}");
		//System.out.println(sb);
		getHttpServletResponse().getWriter().print(sb);
	}


	public String gotoMain(){
		return "main";
	}

	public DcfsJzSbJbxx getDcfsJzSbJbxx() {
		return dcfsJzSbJbxx;
	}

	public void setDcfsJzSbJbxx(DcfsJzSbJbxx dcfsJzSbJbxx) {
		this.dcfsJzSbJbxx = dcfsJzSbJbxx;
	}

	public DcfsMgdJbxx getDcfsMgdJbxx() {
		return dcfsMgdJbxx;
	}

	public void setDcfsMgdJbxx(DcfsMgdJbxx dcfsMgdJbxx) {
		this.dcfsMgdJbxx = dcfsMgdJbxx;
	}

	public DcfsHjjcdJbxx getDcfsHjjcdJbxx() {
		return dcfsHjjcdJbxx;
	}

	public void setDcfsHjjcdJbxx(DcfsHjjcdJbxx dcfsHjjcdJbxx) {
		this.dcfsHjjcdJbxx = dcfsHjjcdJbxx;
	}
	
	
}
